#include<bits/stdc++.h>
#define int long long 
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
} 
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
const int N = 1e5+10,inf = 1e18;
struct node{
	int x,y;
	bool operator < (const node &p) const {return x+y<p.x+p.y;}
}a[N];
int n,ans = inf;
bool cmp(node x,node y){return x.y<y.y;}
multiset<node>s;
multiset<node>::iterator it;
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n = read();
	for(int i = 1;i<=n;i++) a[i] = (node){read(),read()},s.insert(a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i = 1;i+2<=n;i++){
		s.erase(s.find(a[i]));
		it = s.begin();
		node l = *it;it++;
		int res=l.x+l.y+a[i].x;
		l=*it,res+=l.x+l.y;
		ans = min(ans,res);
	}
	write(ans);
	return 0;
}
